//
//  DiscountCollectionViewCell.m
//  PTravel
//
//  Created by dllo on 15/11/26.
//  Copyright © 2015年 李涵. All rights reserved.
//

#import "DiscountCollectionViewCell.h"

@implementation DiscountCollectionViewCell
- (void)dealloc
{
    [_discountLabel release];
    [_timeImage release];
    [_timeLabel release];
    [_titleLabel release];
    [_discountLabel release];
    [_image release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changColor) name:@"night" object:nil];
    if (self) {
        [self createSubViews];
    }
    return self;
}

- (void)changColor
{
    self.backgroundColor = CELLCOLOR;
}

- (void)createSubViews
{
    self.backgroundColor = CELLCOLOR;
    self.image = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.contentView.frame.size.width, BOUNDS.size.height/6)];
    //self.image.backgroundColor = [UIColor yellowColor];
    [self addSubview:self.image];
    [_image release];
    
    self.aview = [[UIView alloc] initWithFrame:CGRectMake(0, self.image.frame.origin.y+self.image.frame.size.height, self.contentView.frame.size.width, 4)];
    [self.contentView addSubview:self.aview];
    
    self.iconImage = [[UIImageView alloc] initWithFrame:CGRectMake(self.contentView.frame.size.width-27, self.image.frame.size.height-10, 20, 20)];
    self.iconImage.layer.masksToBounds = YES;
    self.iconImage.layer.cornerRadius = 10;
    [self.contentView addSubview:self.iconImage];
    
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, self.image.frame.size.height, self.contentView.frame.size.width-10, 60)];
    self.titleLabel.font = [UIFont systemFontOfSize:14];
    self.titleLabel.numberOfLines = 2;
    [self.contentView addSubview:self.titleLabel];
    [_titleLabel release];
    
    self.timeImage = [[UIImageView alloc] initWithFrame:CGRectMake(5, self.titleLabel.frame.origin.y+self.titleLabel.frame.size.height+5, 12, 12)];
    self.timeImage.image = [UIImage imageNamed:@"iconfont-shizhong.png"];
    [self.contentView addSubview:self.timeImage];
    [_timeLabel release];
    
    self.timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, self.titleLabel.frame.origin.y+self.titleLabel.frame.size.height, self.contentView.frame.size.width-25, 20)];
    self.timeLabel.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:self.timeLabel];
    [_timeLabel release];
    
    self.discountLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, self.contentView.frame.size.height-30, 40, 15)];
    self.discountLabel.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:self.discountLabel];
    [_discountLabel release];
    
    self.priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.contentView.frame.size.width-85, self.discountLabel.frame.origin.y, 80, 20)];
    //self.priceLabel.backgroundColor = [UIColor greenColor];
    self.priceLabel.font = [UIFont systemFontOfSize:14];
    [self.contentView addSubview:self.priceLabel];
    [_priceLabel release];
    
}

- (void)setDiscount:(Discount *)discount
{
    if (_discount != discount) {
        [_discount release];
        _discount = [discount retain];
    }
    
    self.titleLabel.text = discount.title;
    self.timeLabel.text = discount.departureTime;
    self.discountLabel.text = discount.lastminute_des;
    self.priceLabel.text = [AppTools flattenHTML:discount.price];
    NSURL *url = [NSURL URLWithString:discount.pic];
    [self.image sd_setImageWithURL:url placeholderImage:IMAGE];
    self.titleLabel.textColor = TEXTCOLOR;
    self.timeLabel.textColor = TEXTCOLOR;
    self.discountLabel.textColor = TEXTCOLOR;
    self.priceLabel.textColor = TEXTCOLOR;
    //飞机
    if ([discount.productType isEqualToString:@"1016"]) {
        self.aview.backgroundColor = [UIColor colorWithRed:0.773 green:0.270 blue:0.328 alpha:1.000];
        self.iconImage.backgroundColor = [UIColor colorWithRed:0.773 green:0.270 blue:0.328 alpha:1.000];
        self.iconImage.image = [UIImage imageNamed:@"iconfont-tubiao11.png"];
    }
    if ([discount.productType isEqualToString:@"1017"]) {
        self.aview.backgroundColor = [UIColor colorWithRed:1.000 green:0.790 blue:0.043 alpha:1.000];
        self.iconImage.backgroundColor = [UIColor colorWithRed:0.323 green:0.723 blue:0.690 alpha:1.000];
        self.iconImage.image = [UIImage imageNamed:@"iconfont-jiudian"];
    }
    if ([discount.productType isEqualToString:@"1018"]) {
        self.aview.backgroundColor = [UIColor colorWithRed:0.323 green:0.723 blue:0.690 alpha:1.000];
        self.iconImage.backgroundColor = [UIColor colorWithRed:0.323 green:0.723 blue:0.690 alpha:1.000];
        self.iconImage.image = [UIImage imageNamed:@"iconfont-tripxingchengxu.png"];
    }
    if ([discount.productType isEqualToString:@"1019"]) {
        self.aview.backgroundColor = [UIColor cyanColor];
        self.iconImage.backgroundColor = [UIColor colorWithRed:0.323 green:0.723 blue:0.690 alpha:1.000];
        self.iconImage.image = [UIImage imageNamed:@"iconfont-tripxingchengxu.png"];
    }
    if ([discount.productType isEqualToString:@"1020"]) {
        self.aview.backgroundColor = [UIColor colorWithRed:0.773 green:0.270 blue:0.328 alpha:1.000];
        self.iconImage.backgroundColor = [UIColor colorWithRed:0.773 green:0.270 blue:0.328 alpha:1.000];
        self.iconImage.image = [UIImage imageNamed:@"iconfont-tubiao11.png"];
    }
    if ([discount.productType isEqualToString:@"1021"]) {
        self.aview.backgroundColor = [UIColor colorWithRed:0.323 green:0.723 blue:0.690 alpha:1.000];
        self.iconImage.backgroundColor = [UIColor colorWithRed:0.323 green:0.723 blue:0.690 alpha:1.000];
        self.iconImage.image = [UIImage imageNamed:@"iconfont-tripxingchengxu.png"];
    }
    if ([discount.productType isEqualToString:@"1049"]) {
        self.aview.backgroundColor = [UIColor colorWithRed:0.323 green:0.723 blue:0.690 alpha:1.000];
        self.iconImage.backgroundColor = [UIColor colorWithRed:0.323 green:0.723 blue:0.690 alpha:1.000];
        self.iconImage.image = [UIImage imageNamed:@"iconfont-tripxingchengxu.png"];
    }
    if ([discount.productType isEqualToString:@"2410"]) {
        self.aview.backgroundColor = [UIColor colorWithRed:0.323 green:0.723 blue:0.690 alpha:1.000];
        self.iconImage.backgroundColor = [UIColor colorWithRed:0.323 green:0.723 blue:0.690 alpha:1.000];
        self.iconImage.image = [UIImage imageNamed:@"iconfont-tripxingchengxu.png"];
    }

    
}

@end
